#!/bin/sh

set -ex

index="${1}"
shift 1
cores="${1}"
shift 1

set +e

region="${1:-europe-west4-a}"
shift 1
version="${1:-1.15}"
shift 1
network="${1:-tpu-euw4a}"
shift 1

set +x

cidr="10.$(math $index + 2).0.0/$(python3 -c "import math; import sys; print(int(32 + 2 - math.log2(int(sys.argv[1]))))" ${cores})"

cat <<EOF
gcloud compute tpus create tpu-v3-${cores}-euw4a-${index} --zone ${region} --project gpt-2-15b-poetry --network ${network} --range ${cidr} --version ${version} --accelerator-type v3-${cores} --preemptible
EOF
